<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas{
            margin-left: 500px;
        }
    </style>
</head>
<body>
    <canvas width="600" height="400">您的浏览器不支持canvas画布标签</canvas>
    <script>
        var data = [6, 30, 10, 8, 3];
        var sum = 0;
        data.forEach( function( item ){
            sum += item;
        });
        var newData = data.map( function( item ){
            return item / sum * (2 * Math.PI);
        });

        var canvas = document.querySelector("canvas");
        var ctx = canvas.getContext("2d");
        var x = ctx.canvas.width / 2;
        var y = ctx.canvas.height / 2;
        var radius = 100;
        var startAngle = 0;
        var endAngle = 0;

        for(var i = 0 ; i < newData.length; i++ ){
            endAngle = startAngle + newData[i];
            ctx.beginPath();
            ctx.moveTo( x, y );
            ctx.arc( x, y,radius,startAngle,endAngle );
            ctx.fillStyle = "#" + Math.random().toString( 16 ).substr(2,6);
            ctx.fill();
            startAngle = endAngle;
        }
    </script>
</body>
</html>